﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class UIManager : UnitySingleton<UIManager> {

	public GameObject pannelReady;//准备面板
	public GameObject pannelStart;//开始面板
	public GameObject pannelOver;//结束面板
	public Slider hpBar;//血条
	public Text lifeText;//生命数
	public GameObject uiLevelStart;//关卡开始显示面板
	public GameObject uiLevelEnd;//通关显示面板

    private Player player;

	
	void Start () {
        player = FindObjectOfType<Player>();
    }
	
	
	void Update () {
        if (!pannelStart.activeInHierarchy)
            return;
        hpBar.value = Mathf.Lerp (hpBar.value, player.hp, 0.1f);
        lifeText.text = player.life.ToString();

    }

    //关卡刚开始
	public void UIlevel(string name)
	{
		uiLevelStart.SetActive (true);
		uiLevelStart.GetComponentInChildren<Text>().text = name;
	}

    //通关
    public void UIend()
    {
        uiLevelEnd.SetActive(true);
        Game.Instance.ReGame();
    }

    //根据status切换三个面板的显示与隐藏
	public void UIChange(Game_Status status)
	{
		pannelReady.SetActive (status == Game_Status.Ready);
		pannelStart.SetActive (status == Game_Status.Start);
		pannelOver.SetActive (status == Game_Status.Over);
	}
}
